<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>修改密码</title>
    <th:block th:include="common.html :: source"></th:block>
</head>
<script>
    function check() {
        var url = "";
        var password2 = $("#password2").val();
        if(password2.length == 0){
            $.messager.alert("操作提示", "密码不能为空！","error");
            $("#password2").focus();
            return false;
        }
        if(password2.length > 20){
            $.messager.alert("操作提示", "验证密码长度过长！","error");
            $("#password2").focus();
            return false;
        }
        $.post(
            '/login/verifyPassword?password='+password2,
            function (data) {
                if (data == 'success') {
                    $("#yz").hide();
                    $("#div1").show();
                    $("#div2").show();
                    $("#div3").show();
                } else {
                    $.messager.alert("操作提示", "密码验证失败！","error");
                    $("#password2").focus();
                    return false;
                }
            }
        );
    }

    function savePwd() {
        var password = $("#password").val();
        var password3 = $("#password3").val();
        var regular = /\s+/g;
        if(regular.test(password)){
            $.messager.alert("操作提示", "登录密码中不能含有空格！","error");
            return false;
        } else {
            if(password == password3){
                if(password=='' || password.length > 20){
                    $.messager.alert("操作提示", "密码长度为1-20！","error");
                    return false;
                } else {
                    $.post(
                        '/login/updatePassword?password='+password,
                        function (data) {
                            if (data == 'success') {
                                $.messager.alert("操作提示", "密码修改成功，请重新登录！","info",function () {
                                    window.close();
                                    window.open('/login/exit');
                                    return true;
                                });
                                return true;
                            } else {
                                $.messager.alert("操作提示", "密码修改失败！","error");
                                return false;
                            }
                        }
                    );
                }
            } else {
                $.messager.alert("操作提示", "新密码与确认密码不一致！","error");
                return false;
            }
        }
    }
</script>
<body>
<center>
    <form name="form1" id="form1">
        <br/><br/><br/><br/><br/><br/><br/><br/>
        <div style="margin-bottom:20px" id="yz">
            <label class="label-top">原始密码:</label>
            <input  type="password" name="password2" id="password2"    style="width:530px;">
            <a class="easyui-linkbutton" onclick="check()">验证密码</a>
        </div>
        <div style="display: none" id="div1">
            <label class="label-top">新密码:</label>
            <input   type="password" name="password" id="password" style="width:600px;">
        </div>
        <br/><br/><br/>
        <div style="display: none" id="div2">
            <label class="label-top">确认新密码:</label>
            <input type="password" name="password3" id="password3" style="width:600px;">
        </div>
        <br/><br/><br/>
        <div style="display: none" id="div3">
            <a class="easyui-linkbutton" onclick="savePwd()">保存</a>
        </div>
    </form>
</center>

</body>
</html>
